Repository navigation
Let the client send a PreparedEvent, not only an Event (2.0) - #16
Merged
Merged
Conversation
loevgaard
force-pushed
the
send-prepared-payload
branch
from
September 21, 2026 07:39
7c33bf6 to
7d7f1e1
Compare
loevgaard
force-pushed
the
send-prepared-payload
branch
from
September 21, 2026 07:52
7d7f1e1 to
9eaf315
Compare
A consumer that hashes the personal data at capture time and sends later, e.g. through a queue, could neither queue the Event (User holds the raw PII until the payload is built) nor hand the finished payload back to the client, which only accepted an Event. Event::prepare() now returns a PreparedEvent: the payload, already normalized and hashed, together with the delivery information (event name and id, the pixels and the test event code). It is made of scalars, arrays and Pixel objects only, so it serializes without any tricks. ClientInterface gains sendPreparedEvent() to send it, and Client::sendEvent() is a one-line delegation to it. The pixels are cloned, so the prepared event is a snapshot, and PreparedEvent::withoutAccessTokens()/withAccessTokens() keep the access tokens out of the queue and restore them by pixel id before sending. "Payload" keeps its 1.x meaning, the array returned by getPayload(); the new object is named for what it is, the payload plus where to send it. The added interface method is the only BC break. See UPGRADE-2.0.md. Closes #15
loevgaard
force-pushed
the
send-prepared-payload
branch
from
September 21, 2026 08:00
9eaf315 to
fbfe481
Compare
This was referenced Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First change of the 2.0 line (base:
2.x). Closes #15.A consumer that hashes the personal data at capture time and sends later (e.g. through a queue) could neither queue the
Event—Userholds the raw PII until the payload is built — nor hand a finished payload back to the client, which only accepted anEvent. The bundle works around that today with aPreparedEventsubclass (MetaConversionsApiBundle#49).Event::prepare(): PreparedEvent— the payload (already normalized and hashed) together with the delivery information:eventName,eventId,payload,pixels,testEventCode. Scalars, arrays andPixelobjects only, so it round-trips throughserialize()(tested) and the Symfony serializer without tricks.ClientInterface::sendPreparedEvent(PreparedEvent)sends it;Client::sendEvent()is now a one-line delegation, so both paths produce byte-identical requests (tested).PreparedEvent::withoutAccessTokens()/withAccessTokens(array $accessTokensByPixelId)— immutable; keep the access tokens out of the queue (and any failure storage behind it) and restore them by pixel id before sending. Pixels missing from the list are left as they are, and numeric pixel ids work as array keys (tested).prepare()clones the pixels, so the prepared event is a true snapshot: changing a pixel on the event or on the prepared event no longer leaks into the other.prepare()->withoutAccessTokens()andwithAccessTokens().Naming, relative to the proposal in #15
The issue proposed
Payload/toPayload()/sendPayload(). That leftEventwith bothgetPayload()andtoPayload(), and the object called "payload" also carried pixels, access tokens and the test event code, which are delivery information rather than payload. So "payload" keeps its 1.x meaning (the array fromgetPayload(), matching thePAYLOAD_CONTEXT_*constants), and the new object is named for what it is: the payload plus where to send it. Its array property is accordinglyPreparedEvent::$payload.Backwards-compatibility break (see
UPGRADE-2.0.md)ClientInterfacegainssendPreparedEvent()— custom implementations must add it. That is the only break;getPayload()is untouched. The Roave BC job on this PR is red by design, since it compares against2.x, which is still 1.x code.Not in this PR (candidates for further 2.0 PRs)
Fbp::$randomNumberbeing public/mutable, native union types forUser::$fbc/$fbpandFb::withCreationTime(), aPayloadContextenum, and thehaven'ntypo in the client's log message.Test plan
EventTest::it_prepares— hashed payload, pixels, test event code;eventName/eventIdmatch the payload; the raw email never appears in the serialized prepared eventClientTest::it_sends_prepared_event,it_sends_the_same_request_for_an_event_and_its_prepared_event,it_does_not_send_prepared_event_when_it_has_no_pixelsPreparedEventTest—serialize()/unserialize()round trip incl. a token-less pixel;withoutAccessTokens()andwithAccessTokens()(immutability, numeric pixel ids, untouched and replaced tokens)EventTest::it_prepares_a_snapshot— pixels are cloned in both directionsClientTest::it_sends_a_prepared_event_that_was_queued_without_its_access_tokens— strip, serialize, unserialize, restore, send: byte-identical tosendEvent(), and the serialized form contains no tokenAfter this is released
The bundle deletes its
PreparedEventsubclass; itsSendEventmessage carries$event->prepare()->withoutAccessTokens(), and the handler resolves the tokens and callssendPreparedEvent($preparedEvent->withAccessTokens($tokens)).